<meta charset="UTF-8">
<?php
$conn = mysqli_connect('localhost' , 'root' , '');
mysqli_query($conn,'use blog;');
mysqli_query($conn,'set names utf8;');
$cat_id = $_GET['cat_id'];
//检测栏目是否合法
if (!is_numeric($cat_id)){
    echo '栏目不合法';
    exit();
}
//检测栏目是否存在
$sql = "select count(*) from cat where cat_id = $cat_id";
$rs = mysqli_query($conn , $sql);
if (mysqli_fetch_row($rs)[0] == 0){
    echo '栏目不存在';
    exit();
}


if (empty($_POST)){
    $sql = "select cat_name from cat where cat_id = $cat_id";
    $rs = mysqli_query($conn,$sql);
    $cat = mysqli_fetch_assoc($rs);
    require ('view/admin/catedit.html');
}else{
    $sql = "update cat set cat_name = '$_POST[catname]' where cat_id=$cat_id";
    if (!mysqli_query($conn,$sql)){
        echo '修改失败';
    }
    else {
        echo '修改成功';
    }

}


?>
